let sscId = $(".select_item_ssc").attr("value");
let ccId = $(".select_item_cc").attr("value");

let notBookedChineseCourseTable;
let ltNotFeedbackTable;
let stuOrderInfoTable;
let absenteeismLessonsTable;
let potentialStuTable;
let inactiveStuTable;
let oldStuFollowTable;

//初始化页面框架
$(function () {
    let configList = selectSort(adminConfig);
    for (let i = 0; i < configList.length; i++) {
        if (configList[i].state != 0) {
            // console.log("sscConfig configList[i].method=>", configList[i].method)
            eval(configList[i].method);
        }
    }

    // 点击关闭按钮
    $(".close_icon").click(function () {
        $(this).parents('.main-box').remove()
    });
});

//点击排序设置，获取 排序列表
function sortConfig() {
    let configList = selectSort(adminConfig);
    //排序列表公共方法
    pubSortList(configList);
}

//还原默认设置 方法
function restoreDefaultConfig() {
    //调用公共方法
    restoreDefault(adminConfig);
}

//待约中教课 1
function notBookedChineseCourse(id, tableName){
    //alert($("#listSsc").find("*").clone(true))
    let html = '<div class="form-inline" style="float: left;margin-right: 10px;">';
    html += '<select id="sscId1" class="form-control" onchange="reloadNotBookedChineseCourseTable()">'
        //+'<option value="">请选择SSC</option> '
        + '</select>';
    html += '<select id="revisitId" class="form-control" onchange="reloadNotBookedChineseCourseTable()"><option value="0">非特殊学员</option><option value="25">特殊学员</option></select>';
    html += '</div>';
    pubHtml(id, 3, tableName, html, "");
    $("#sscId1").append($("#listSsc").find("*").clone(true));
    //$("#sscId1").selectpicker('refresh');

}
//待约中教课 1
layui.use('table', function () {
    let table = layui.table;
    notBookedChineseCourseTable = table
    table.render({
        elem: "#1",
        url: '/adminNewMain/not/booked/lt/class/list',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"sscId": $("#sscId1").val(),"revisitId": $("#revisitId").val()},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学生登录名', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.personId + ',\'' + row.cnName + '\',26)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'releaseTime', title: '最后完成中教课时间', fixed: 'left',
                    templet: function (row) {
                        return '<span>' + formatDateMin(row.releaseTime) + '</span>';
                    }
                },
                {field: 'sscName', title: 'SSC', fixed: 'left'},
                {field: 'ccName', title: 'CC', fixed: 'left'},
            ]
        ],
        id: "notBookedChineseCourse"
    });
});
// 待约中教课学员 reload
function reloadNotBookedChineseCourseTable() {
    notBookedChineseCourseTable.reload("notBookedChineseCourse", {
        page: {
            curr: 1 ,//重新从第 1 页开始
        }, where: {
            "revisitId": $("#revisitId").val(),
            "sscId": $("#sscId1").val()
        }
    });
}

//待提交阶段检测报告 2
function ltNotFeedback(id, tableName){
    let html = '<div class="form-inline" style="float: left;margin-right: 10px;">';
    html += '<select id="sscId2" class="form-control" onchange="reloadLtNotFeedbackTable()">'
        +'<option value="">请选择SSC</option> '
        + '</select>';
    html += '</div>';
    pubHtml(id, 1, tableName, html, "");
    $("#sscId2").append($("#listSsc").find("*").clone(true));
}
//待提交阶段检测报告 16
layui.use('table', function () {
    let table = layui.table;
    ltNotFeedbackTable = table
    table.render({
        elem: "#2",
        url: '/adminNewMain/not/lt/feedback/list',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"sscId": $("#sscId2").val()},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学生登录名', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.personId + ',\'' + row.cnName + '\',27)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left',
                    templet: function (row) {
                        let td= row.cnName;
                        if (row.newUser===1){
                            td+='&nbsp;&nbsp;<img alt="" src="../../static/img/new.gif">';
                        }
                        return td;
                    }},
                {field: 'releaseTime', title: '完成检测课时间', fixed: 'left',
                    templet: function (row) {
                        return '<span>' + formatDateMin(row.releaseTime) + '</span>';
                    }
                },
                {field: 'sscName', title: 'SSC', fixed: 'left'},
                {field: 'ccName', title: 'CC', fixed: 'left'},
            ]
        ],
        id: "ltNotFeedback"
    });
});
// 待提交阶段检测报告 reload
function reloadLtNotFeedbackTable() {
    ltNotFeedbackTable.reload("ltNotFeedback", {
        page: {
            curr: 1 //重新从第 1 页开始
        }, where: {
            "sscId": $("#sscId2").val()
        }
    });
}

//订单到期外框 5
function stuOrderInfo(id, tableName) {
    let html = '<div class="form-inline" style="float: left;margin-right: 10px;">';
    html += '<select id="sscId5" class="form-control" onchange="reloadStuOrder()">'
        +'<option value="">请选择SSC</option> '
        + '</select>';
    html += '<select id="ccId5" class="form-control" onchange="reloadStuOrder()">'
        +'<option value="">请选择CC</option> '
        + '</select>';
    html += '<select id="days5" class="form-control" onchange="reloadStuOrder()"><option value="30">30天到期</option><option value="60">60天到期</option></select>';
    html += '</div>';
    pubHtml(id, 2, tableName, html, "");
    $("#sscId5").append($("#listSsc").find("*").clone(true));
    $("#ccId5").append($("#listCc").find("optgroup").clone(true));
}

//ssc 订单到期列表渲染 5
layui.use('table', function () {
    let table = layui.table;
    stuOrderInfoTable = table;
    table.render({
        elem: '#5',
        url: '/adminNewMain/order/expire/list',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"sscId": $("#sscId5").val(),"ccId": $("#ccId5").val(),"days": $("#days5").val()},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',0)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'packageName', title: '订单名称', fixed: 'left'},
                {
                    field: 'surplusValid', title: '到期日期', fixed: 'left',
                    templet: function (row) {
                        return FormatTime(row.surplusValid, 0);
                    }
                },
                {field: 'remainingCourses', title: '剩余币/课时数', fixed: 'left'},
                {field: 'sscName', title: 'SSC', fixed: 'left'},
                {field: 'ccName', title: 'CC', fixed: 'left'},
            ]
        ],
        id: "stuOrderInfo"
    });
});

//订单到期 reload
function reloadStuOrder() {
    stuOrderInfoTable.reload("stuOrderInfo", {
        page: {
            curr: 1 //重新从第 1 页开始
        },
        where: {
            "sscId": $("#sscId5").val(),
            "ccId": $("#ccId5").val(),
            "days": $("#days5").val()
        }
    });
}

//老学员跟进 3
function oldStuFollow(id, tableName) {
    let html = '<div class="form-inline" style="float: left;margin-right: 10px;">';
    html += '<select id="sscId3" class="form-control" onchange="reloadOldStuFollow()">'
        +'<option value="">请选择SSC</option> '
        + '</select>';
    html += '<select id="ccId3" class="form-control" onchange="reloadOldStuFollow()">'
        +'<option value="">请选择CC</option> '
        + '</select>';
    html += '<select id="followDays" class="form-control" onchange="reloadOldStuFollow()">' +
        '<option value="">未回访天数</option>' +
        '<option value="10">10~19天</option>' +
        '<option value="20">20~29天</option>' +
        '<option value="30">>=30天</option>' +
        '</select>';
    html += '</div>';
    pubHtml(id, 4, tableName, html, "");
    $("#sscId3").append($("#listSsc").find("*").clone(true));
    $("#ccId3").append($("#listCc").find("optgroup").clone(true));
}

//ssc 老学员跟进 列表渲染 4
layui.use('table', function () {
    let table = layui.table;
    oldStuFollowTable = table;
    table.render({
        elem: '#3',
        url: '/adminNewMain/old/stu/follow/list',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"sscId": $("#sscId3").val(),"ccId": $("#ccId3").val(),"followDays": $("#followDays").val()},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',7)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'testMark', title: '未回访天数', fixed: 'left'},
                {field: 'sscName', title: 'SSC', fixed: 'left'},
                {field: 'ccName', title: 'CC', fixed: 'left'}
            ]
        ],
        id: "oldStuFollow"
    });
});

//老学员跟进 reload
function reloadOldStuFollow() {
    oldStuFollowTable.reload("oldStuFollow", {
        page: {
            curr: 1 //重新从第 1 页开始
        },where: {
            "sscId": $("#sscId3").val(),
            "ccId": $("#ccId3").val(),
            "followDays": $("#followDays").val()
        }
    });
}

//潜在客户 7
function potentialStu(id,tableName){
    let html = '<div class="form-inline" style="float: left;margin-right: 10px;">';
    html += '<select id="ccId7" class="form-control" onchange="reloadPotentialStu()">'
        +'<option value="">请选择CC</option> '
        + '</select>';
    html += '</div>';
    pubHtml(id, 2, tableName, html, "");
    $("#ccId7").append($("#listCc").find("optgroup").clone(true));
}

//cc 潜在客户 7
layui.use('table', function(){
    let table = layui.table;
    potentialStuTable = table;
    table.render({
        elem: '#7',
        url:'/adminNewMain/potential/stu/list',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where:{"ccId" :  $("#ccId7").val(),"state" : 1},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {field:'stuLoginName', title: '学号',fixed: 'left',
                    templet : function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo('+row.id+',\''+row.cnName+'\',13)">'+row.stuLoginName+'</a>';
                    }
                },
                {field:'cnName', title: '姓名',fixed: 'left'},
                {field:'channelName', title: '客户渠道',fixed: 'left'},
                {field: 'ccName', title: 'CC', fixed: 'left'},
                {field:'releaseTime', title: '注册时间', fixed: 'left',
                    templet : function (row) {
                        return FormatTime(row.releaseTime,1);
                    }
                }
            ]
        ],
        id : "potentialStu"
    });
});

//潜在客户 reload
function reloadPotentialStu(){
    potentialStuTable.reload("potentialStu", {
        page: {
            curr: 1 //重新从第 1 页开始
        },
        where : {
            "ccId": $("#ccId7").val(),
            "state" : 1
        }
    });
}

//近月旷课3次以上学员 4
function absenteeismLessons(id, tableName) {
    let html = '<div class="form-inline" style="float: left;margin-right: 10px;">';
    html += '<select id="sscId4" class="form-control" onchange="reloadAbsenteeismLessons()">'
        +'<option value="">请选择SSC</option> '
        + '</select>';
    html += '<select id="ccId4" class="form-control" onchange="reloadAbsenteeismLessons()">'
        +'<option value="">请选择CC</option> '
        + '</select>';
    html += '</div>';
    pubHtml(id, 2, tableName, html, "");
    $("#sscId4").append($("#listSsc").find("*").clone(true));
    $("#ccId4").append($("#listCc").find("optgroup").clone(true));
}

//近月旷课3次以上学员 列表渲染 4
layui.use('table', function () {
    let table = layui.table;
    absenteeismLessonsTable = table;
    table.render({
        elem: '#4',
        url: '/adminNewMain/absenteeism/lesson/list',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"ccId": $("#ccId4").val(),"sscId": $("#sscId4").val()},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',\'s1\')">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'totalNoShow', title: '近30天次数', fixed: 'left'},
                {field: 'remark', title: '新增次数', fixed: 'left'},
                {field: 'sscName', title: 'SSC', fixed: 'left'},
                {field: 'ccName', title: 'CC', fixed: 'left'}
            ]
        ],
        id: "absenteeismLessons"
    });
});

//近月旷课3次以上学员面板  点击完成并发布动态后，重新加载该面板
function reloadAbsenteeismLessons() {
    absenteeismLessonsTable.reload("absenteeismLessons", {
        page: {
            curr: 1 //重新从第 1 页开始
        },
        where : {
            "ccId": $("#ccId4").val(),
            "sscId": $("#sscId4").val(),
        }
    });
}

//Inactive学员 6
function inactiveLessons(id, tableName) {
    let html = '<div class="form-inline" style="float: left;margin-right: 10px;">';
    html += '<select id="sscId6" class="form-control" onchange="reloadInactiveStu()">'
        +'<option value="">请选择SSC</option> '
        + '</select>';
    html += '<select id="ccId6" class="form-control" onchange="reloadInactiveStu()">'
        +'<option value="">请选择CC</option> '
        + '</select>';
    html += '</div>';
    pubHtml(id, 1, tableName, html, "");
    $("#sscId6").append($("#listSsc").find("*").clone(true));
    $("#ccId6").append($("#listCc").find("optgroup").clone(true));
}

//Inactive学员 列表渲染 6
layui.use('table', function () {
    let table = layui.table;
    inactiveStuTable = table;
    table.render({
        elem: '#6',
        url: '/adminNewMain/inactive/lesson/list',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {"ccId": $("#ccId6").val(),"sscId": $("#sscId6").val()},
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {
                    field: 'stuLoginName', title: '学号', fixed: 'left',
                    templet: function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo(' + row.id + ',\'' + row.cnName + '\',0)">' + row.stuLoginName + '</a>';
                    }
                },
                {field: 'cnName', title: '姓名', fixed: 'left'},
                {field: 'days', title: '未约课天数', fixed: 'left'},
                {field: 'sscName', title: 'SSC', fixed: 'left'},
                {field: 'ccName', title: 'CC', fixed: 'left'}
            ]
        ],
        id: "inactiveStu"
    });
});

//Inactive学员 reload
function reloadInactiveStu() {
    inactiveStuTable.reload("inactiveStu", {
        page: {
            curr: 1 //重新从第 1 页开始
        },
        where : {
            "ccId": $("#ccId6").val(),
            "sscId": $("#sscId6").val(),
        }
    });
}

//提醒列表 8
function trackRemind(id,tableName){
    let html = '<div class="form-inline" style="float: left;margin-right: 10px;">';
    html += '<select id="ccId8" class="form-control selectpicker" data-width="fit" title="请选择CC" multiple onchange="reloadTrackRemind()">'
        //+'<option value="">请选择CC</option> '
        + '</select>';
    html += '<span class="date_box">';
    html +='   <a href="javascript:" style="color: #fff" id="trackRemindDate">2019-01-07</a>';
    html +='<i class="fa fa-calendar" style="margin-left: 5px"></i>';
    html +='</span>';
    html += '</div>';
    pubHtml(id,3,tableName,html,"");
    $("#ccId8").append($("#listCc").find("optgroup").clone(true));
    $("#ccId8").selectpicker('refresh');
}
//cc 提醒数据表渲染 8
layui.use(['table','laydate'], function(){
    let table = layui.table;
    let laydate = layui.laydate;
    trackRemindTable = table;
    table.render({
        elem: '#8',
        url:'/adminNewMain/track/remind/list',
        method: 'POST', //方式
        height: "400",
        loading: true, //翻页加loading
        where: {
            "ccId": $("#ccId8").val()+""
        },
        page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 5, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false, //不显示尾页
            theme: '#00A0E9'
        },
        cols: [
            [
                {field:'stuLoginName', title: '学号',fixed: 'left',width: '140',
                    templet : function (row) {
                        return '<a href="javascript:void(0);" onclick="personInfo('+row.id+',\''+row.cnName+'\',10,'+row.remindId+')">'+row.stuLoginName+'</a>';
                    }},
                {field:'cnName', title: '姓名',fixed: 'left',width: '100'},
                {field: 'releaseTime', title: '提醒时间',fixed: 'left',width: '160',
                    templet :function (row){
                        if (row.expired==1){
                            return '<span style="color: #bd2130;">'+FormatTime(row.releaseTime)+'</span>';
                        }else {
                            return '<span style="color: #1abd76;">'+FormatTime(row.releaseTime)+'</span>';
                        }
                    }
                },
                {field:'remark', title: '客户属性',fixed: 'left',width: '132'},
                {field:'ccName', title: 'CC',fixed: 'left',width: '160'},
                {field:'creator', title: '创建人',fixed: 'left',width: '120'}
            ]
        ],
        id : "trackRemind"
    });
    //日期插件  重新加载
    laydate.render({
        elem:"#trackRemindDate",//制定元素
        value: new Date(),
        done:function(value,date){//value, date, endDate点击日期、清空、现在、确定均会触发。回调返回三个参数，分别代表：生成的值、日期时间对象、结束的日期时间对象
            //执行重载
            alert($("#ccId8").val())
            table.reload("trackRemind", {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    "searchDate" : value,
                    "ccId": $("#ccId8").val()+""
                }
            });
        }
    });
});

//提醒列表 reload
function reloadTrackRemind(){
    trackRemindTable.reload("trackRemind", {
        page: {
            curr: 1 //重新从第 1 页开始
        },
        where: {
            "searchDate" : $("#trackRemindDate").text(),
            "ccId": $("#ccId8").val()+""
        }
    });
}
